<?php

use Biz\service\GoodsTestActivity\FineGoodsService;

/**
 * 活动报告
 * Class ListAction
 */
class ReportAction extends ActionPlugin
{
    public const USER_LEVEL = self::LEVEL_NOTHING;
    private const PAGE_SIZE = 20;

    public function main()
    {
        $uid = $this->uid;
        $page = $this->getRequest()->getPost('page', 1);
        $per_page = $this->getRequest()->getPost('per_page', self::PAGE_SIZE);
        $category_tag = $this->getRequest()->getPost('category_tag', 0);
        //活动分类标签（0:全部、1:家具、2:日用、3:装饰、4:家电、5:灯饰、6:宠物）
        //偏移量，当前页-1乘以每页显示条数
        $start = ($page - 1) * $per_page;
        $field = [
            'id',
            'type',
            'brand_id',
            'brand_name',
            'basic_title',
            'activity_title',
            'goods_worth',
            'goods_max_worth',
            'goods_num',
//            'activity_state',
            'cover_img',
            'report_num',
            'evaluation_id',
            'category_tag_id'
        ];
        $data = FineGoodsService::getReportList($category_tag, $start, $per_page, $field);
        $total = $data['total'] ?? 0;
        $current = $page * $per_page;
        $res['list'] = $data['list'] ?? [];
        $res['total'] = $data['total'] ?? 0;
        $res['is_over'] = ($total <= $current) ? 1 : 0;
        $res['current_page'] = $page;
        $fine_goods_ids = array_column($res['list'], 'id');
        if (!$res['list']) {
            return $this->setSuccess($res);
        }
        $contents = FineGoodsService::getNoteListById($fine_goods_ids, $uid);
        foreach ($res['list'] as &$v) {
            $v['report_list'] = $contents[$v['id']] ?? [];

        }
        $this->setSuccess($res);
    }
}


